package com.stjb.furns.dao.impl;

import com.stjb.furns.dao.BasicDAO;
import com.stjb.furns.dao.OrderDAO;
import com.stjb.furns.entity.Order;

import java.util.List;

/**
 * @author situ
 * @version 1.0
 * @date 2025/5/29 20:47
 * @Description:
 */
public class OrderDAOImpl extends BasicDAO<Order> implements OrderDAO {

    /**
     * 购物车结算时保存订单信息
     * @param order
     * @return
     */
    @Override
    public int saveOrder(Order order) {
        String sql = "insert into `order` (`id`,`create_time`,`price`,`status`,`member_id`,`formattedTime`)" +
                "values(?,?,?,?,?,?)";
        return update(sql,order.getId(),
                order.getCreateTime(),order.getPrice(),order.getStatus()
                ,order.getMemberId(), order.getFormattedTime());
    }

    /**
     * 根据传入的id返回查询到的所有订单
     * @param userid
     * @return
     */
    @Override
    public List<Order> queryOrderByMemberId(int userid) {
        String sql = "select `id`,`create_time`,`price`,`status`,`formattedTime` from `order`where member_id = ?";
        return queryMulti(sql,Order.class,userid);
    }


}
